package com.ibeifeng.crm.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import com.ibeifeng.crm.bean.Course;
import com.ibeifeng.crm.dao.CourseDao;

@Repository
public class CourseDaoImpl implements CourseDao {
	Logger log = Logger.getLogger(CourseDaoImpl.class);
	
	@Resource
	SqlSessionFactory factory;
	@Override
	public List<Course> queryAll() {
		List<Course> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.CourseNS.queryAll");
		return list;
	}
	@Override
	public int add(Course course) {
		int result = factory.openSession().insert("com.ibeifeng.crm.bean.mapping.CourseNS.insert", course);
		return result;
	}
	@Override
	public int update(Course course) {
		int result = factory.openSession().update("com.ibeifeng.crm.bean.mapping.CourseNS.update", course);
		return result;
	}
	@Override
	public int delete(Course course) {
		int result = factory.openSession().delete("com.ibeifeng.crm.bean.mapping.CourseNS.delete", course);
		
		return result;
	}
	@Override
	public Course queryCourse(Course course) {
		Course cou = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.CourseNS.findById", course);
		return cou;
	}
	@Override
	public int count() {
		int count = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.CourseNS.count");
		return count;
	}
	@Override
	public List<Course> findAllSplit(int pg, int pgSize) {
		Map map = new HashMap();
		int start=(pg-1)*pgSize;
		int pageSize = pgSize;
		map.put("start", start);
		map.put("pageSize", pgSize);
		List<Course> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.CourseNS.findAllSplit",map);
		return list;
	}

}
